package com.ruoyi.common.customize.util.serializer;


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.ruoyi.common.customize.util.BigDecimalUtils;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * BigDecimal序列化为plainString
 *
 * @author gdk
 * @date 2022/8/24 22:11
 */
public class BigDecimalToPlainStringSerializer extends JsonSerializer<BigDecimal> {
    /**
     * BigDecimal反序列化器
     *
     * @param value
     * @param jsonGenerator
     * @param serializerProvider
     * @author gdk
     * @date 2022/8/24 22:15
     */
    @Override
    public void serialize(BigDecimal value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String s = BigDecimalUtils.toStrRemoveExtraZero(value);
        jsonGenerator.writeString(s);
    }
}
